import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import AutoImport from "unplugin-auto-import/vite";
import UnoCSS from "unocss/vite";
import { fileURLToPath } from "url";
import path from "path";

function resolvePath(paths) {
  return path.resolve(__dirname, paths);
}

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(), // 自动导入 components 下面的组件，无需 import 引入
    Components({
      deep: true,
      extensions: ["vue"],
      dirs: ["src/components"], // 自动导入的组件目录
    }),
    AutoImport({
      imports: ["vue"],
      eslintrc: {
        // 这里先设置成true然后pnpm dev 运行之后会生成 .auto-import.json 文件之后，在改为false
        enabled: true,
        filepath: "./.auto-import.json",
        globalsPropValue: true,
      },
    }),
    UnoCSS({
      configFile: "./uno.config.js",
    }),
  ],
  // 路径别名
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "@views": resolvePath("src/views"),
      "@imgs": resolvePath("src/assets/img"),
      "@icons": resolvePath("src/assets/icons"),
      "@utils": resolvePath("src/utils"),
      "@stores": resolvePath("src/store"),
      "@plugins": resolvePath("src/plugins"),
      "@styles": resolvePath("src/assets/styles"),
    },
  },
});
